<template>
  <!-- 大图-左侧大块 -->
  <div class="img-big">
    <div class="flex">
      <div class="left-img" ref="target">
        <div class="img-posr">
          <img
            src="https://www.dianler.com/wp-content/uploads/2022/08/2022081006105678.jpg"
            alt=""
          />
          <!--蒙层 -->
          <div
            class="mask"
            :style="{ top: `${top}px`, left: `${left}px` }"
            v-show="!isOutside"
          ></div>
          <!-- 放大图 -->
          <div
            class="big-img"
            v-show="!isOutside"
            :style="{
              backgroundImage: `url(https://www.dianler.com/wp-content/uploads/2022/08/2022081006105678.jpg)`,
              backgroundPositionX: `${positionX}px`,
              backgroundPositionY: `${positionY}px`,
            }"
          ></div>
        </div>
      </div>
      <!-- 右侧四个小图 -->
      <div class="right-img">
        <div class="img-box">
          <img
            src="../../../images/all-item.png"
            style="border: 2px solid #27ba9b"
            alt=""
          />
          <img
            src="../../../images/all-item.png"
            alt=""
            v-for="item in 4"
            :key="item"
          />
        </div>
      </div>
    </div>
    <!-- 图片下边的介绍 -->
    <div class="img-bottom">
      <ul style="display: flex">
        <li class="bottom-item" v-for="item in 4" :key="item">
          <p style="color: rgb(153, 153, 153)">销量人气</p>
          <p style="color: rgb(207, 68, 68)">200+</p>
          <p style="color: rgb(102, 102, 102)">❤️销量人气</p>
        </li>
      </ul>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref, watch } from 'vue';
// 引入图片滑块组件
import { useMouseInElement } from '@vueuse/core';
// 获取鼠标相对位置
const target = ref(null);
const { elementX, elementY, isOutside } = useMouseInElement(target);
// 初始值鼠标未知
let left = ref(0);
let top = ref(0);
// 大图
let positionX = ref(0);
let positionY = ref(0);
// 侦听鼠标变化，进行赋值left top
watch([elementX, elementY], () => {
  if (isOutside.value) return;

  if (elementX.value > 100 && elementX.value < 300) {
    left.value = elementX.value - 100;
  }
  if (elementY.value > 100 && elementY.value < 300) {
    top.value = elementY.value - 100;
  }
  // 大图的位置
  positionX.value = -elementX.value;
  positionY.value = -elementY.value;
});
// 渲染
// const red = defineProps() as string[]
// onMounted(() => {
//   console.log(red)
// })
// type props = {
//   imageList? : string[]
// }
// const p = defineProps<props>()
// console.log(p.imageList)
// watch(p.imageList as string[],(newCount,oldCount)=>{
//   console.log(newCount,oldCount)
// })
</script>
<style scoped lang="less">
.img-big {
  .flex {
    display: flex;

    img {
      width: 400px;
      height: 400px;
      background-color: black;
    }
    .right-img {
      width: 80px;
      height: 400px;
      display: flex;
      margin-left: 10px;
      .img-box {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        align-items: end;
      }
      img {
        width: 68px;
        height: 68px;
      }
    }
  }
  .img-bottom {
    margin-top: 20px;
    .bottom-item {
      width: 100px;
      height: 97px;
      text-align: center;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      position: relative;
      &::before {
        content: '';
        position: absolute;
        top: 10px;
        left: 0px;
        height: 60px;
        border-left: 1px solid #e4e4e4;
        background-color: red;
      }

      p {
        width: 100px;
        height: 33px;
        font-size: 14px;
      }
    }
  }
}
.mask {
  width: 200px;
  height: 200px;
  background-color: rgba(0, 0, 0, 0.2);
  position: absolute;
}
.img-posr {
  width: 400px;
  height: 400px;
  position: relative;
}
.big-img {
  width: 400px;
  height: 400px;
  background-color: black;
  position: absolute;
  top: 0;
  left: 405px;
  background-size: 800px 800px;
  background-repeat: no-repeat;
  z-index: 999999;
}
li.bottom-item:first-child::before {
  display: none;
}
</style>
